package com.myhome.money.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.myhome.money.sentinel.util.ExceptionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 许路路
 * @Date: 2019/8/7
 */
@RestController
@RequestMapping("home")
public class HomeController {

    @GetMapping("index")
    public String index() {
        return "index123";
    }

    @SentinelResource(value = "resource001", blockHandler = "dealEx", blockHandlerClass = ExceptionUtils.class)
    @GetMapping("test01")
    public String annoResource() {
        System.out.println("这是一个正经的方法11111");
        return "这是一个正经的方法11111";
    }

    @SentinelResource(value = "resource002", fallback = "annoResource2FallBack", blockHandler = "handleException")
    @GetMapping("test02")
    public String annoResource2() {
        System.out.println("这是一个正经的方法2222");
        return "这是一个正经的方法2222";
    }

    public String annoResource2FallBack() {
        System.out.println("这是FallBack2222");
        return "这是FallBack2222";
    }

    public String handleException(BlockException ex) {
        System.out.println("这是一个异常处理2222:" + ex.getMessage());
        return "这是一个异常处理2222:" + ex.getMessage();
    }

}
